package com.sino.operation.service.business;

import cn.hutool.core.util.RandomUtil;
import com.sino.operation.peripheral.esc.request.EscAppHead;
import com.sino.operation.peripheral.esc.request.EscSysHead;
import com.sino.operation.peripheral.esc.request.LocalHead;
import com.sino.operation.peripheral.esc.request.core.EscAccountTest;
import com.sino.operation.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @ClassName ObtainEscCoreParamService
 * @Description 获取发往核心的参数
 * @Author 北陈
 * @Date 2021/11/7 23:15
 * @Version 1.0
 */
@Service
@Slf4j
public class ObtainEscCoreParamService {

    @Autowired
    private StringRedisTemplate redis;

    public EscAccountTest getEscCoreParam(String journalNo,String interNo){
        EscAccountTest escAccountTest = new EscAccountTest();
        EscSysHead escSysHead = this.getEscSysHead(journalNo,interNo);
        LocalHead localHead = this.getLocalHead();
        EscAppHead escAppHead = new EscAppHead();
        escAccountTest.setEscAppHead(escAppHead);
        escAccountTest.setEscSysHead(escSysHead);
        escAccountTest.setLocalHead(localHead);
        return escAccountTest;
    }

    public EscSysHead getEscSysHead(String journalNo,String interNo){
        EscSysHead escSysHead = new EscSysHead();
        escSysHead.setServiceCode("SX_BPR_11200");
        escSysHead.setSourceSvrId("10.64.20.145");
        escSysHead.setServiceScene("01");
        escSysHead.setConsumerId("11200");
        escSysHead.setChannelCode("1120000");
        escSysHead.setConsumerSeqNo("BPR0000"+TimeUtil.getDateTime()+RandomUtil.randomNumbers(5));
        escSysHead.setServiceCode(interNo);
        String seq="G11700"+ TimeUtil.getDateTime()+"00000"+ RandomUtil.randomNumbers(5);
        log.info("流水号:"+journalNo+"\n全局流水号:"+seq);
        escSysHead.setBussSeqNo(seq);
        escSysHead.setTranDate(TimeUtil.getDateTime());
        escSysHead.setTranTimestamp(TimeUtil.getTimestamp());
        return escSysHead;
    }

    public LocalHead getLocalHead(){
        String escToken = redis.opsForValue().get("escToken");
        return LocalHead.builder().reqTenant("sxyh").reqPartId("1120000")
                .reqPartVersion("V1.0").reqToken(escToken)
                .svcTranNo("SX_00101_BPR")
                .svcVerNo("V1.0").build();
    }
}
